﻿<UserControl x:Class="TrailMapManager.Modules.Poi.View.PoiMainView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:bing="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF"
             xmlns:converters="clr-namespace:TrailMapManager.Common.Converters;assembly=Common"
             xmlns:logic="clr-namespace:TrailMapManager.Modules.Poi.Logic"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/ModernControls;component/Style.xaml"/>
                <ResourceDictionary>
                    <converters:AddingConverter x:Key="addConv"/>

                    <Style x:Key="poiListItemStyle" TargetType="{x:Type ListBoxItem}">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                    <Grid>
                                        <VisualStateManager.VisualStateGroups>
                                            <VisualStateGroup x:Name="CommonStates">
                                                <VisualState x:Name="Selected">
                                                    <Storyboard>
                                                        <ColorAnimation Storyboard.TargetName="bgBrush"
                                                            Storyboard.TargetProperty="Color"
                                                            To="{StaticResource AppBaseColor}"
                                                            Duration="00:00:00.2"/>
                                                        <ColorAnimation Storyboard.TargetName="textBrush"
                                                            Storyboard.TargetProperty="Color"
                                                            To="White"
                                                            Duration="00:00:00.2"/>
                                                    </Storyboard>
                                                </VisualState>

                                                <VisualState x:Name="Normal">
                                                    <Storyboard>
                                                        <ColorAnimation Storyboard.TargetName="bgBrush"
                                                            Storyboard.TargetProperty="Color"
                                                            To="White"
                                                            Duration="00:00:00.2"/>
                                                        <ColorAnimation Storyboard.TargetName="textBrush"
                                                            Storyboard.TargetProperty="Color"
                                                            To="Black"
                                                            Duration="00:00:00.2"/>
                                                    </Storyboard>
                                                </VisualState>
                                                <VisualState x:Name="MouseOver">
                                                    <Storyboard>
                                                        <ColorAnimation Storyboard.TargetName="bgBrush"
                                                            Storyboard.TargetProperty="Color"
                                                            To="{StaticResource AppBaseLightestColor}"
                                                            Duration="00:00:00.2"/>
                                                        <ColorAnimation Storyboard.TargetName="textBrush"
                                                            Storyboard.TargetProperty="Color"
                                                            To="Black"
                                                            Duration="00:00:00.2"/>
                                                    </Storyboard>
                                                </VisualState>
                                            </VisualStateGroup>
                                        </VisualStateManager.VisualStateGroups>
                                        <Grid.Background>
                                            <SolidColorBrush x:Name="bgBrush" Color="#B2808080"/>
                                        </Grid.Background>
                                        <TextBlock Text="{Binding Name}"
                                                   FontSize="22"
                                                   FontFamily="Segoe UI Light"
                                                   TextTrimming="CharacterEllipsis">
                                            <TextBlock.Foreground>
                                                <SolidColorBrush Color="White" x:Name="textBrush"/>
                                            </TextBlock.Foreground>
                                        </TextBlock>
                                    </Grid>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>

                    <!--<ControlTemplate x:Key="validationErrorTemplate">
                        <Border BorderBrush="Red" BorderThickness="2">
                            <AdornedElementPlaceholder/>
                        </Border>
                    </ControlTemplate>-->

                    <Style x:Key="validationTextbox" TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
                        <Setter Property="Background" Value="White" />
                        <Setter Property="Validation.ErrorTemplate">
                            <Setter.Value>
                                <ControlTemplate>
                                    <Border BorderBrush="Red" BorderThickness="2">
                                        <AdornedElementPlaceholder />
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                        <Style.Triggers>
                            <Trigger Property="Validation.HasError" Value="true">
                                <Setter Property="Background" Value="#FFDDDD"/>
                            </Trigger>
                        </Style.Triggers>
                    </Style>

                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid x:Name="mainGrid">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>


        <Grid Grid.Column="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition MinWidth="50" MaxWidth="260"/>
                <ColumnDefinition MinWidth="200"/>
            </Grid.ColumnDefinitions>

            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition Height="50"/>
                </Grid.RowDefinitions>
                <ListBox ItemsSource="{Binding PoiMan.Points}"
                      SelectedItem="{Binding SelectedPoi, Mode=TwoWay}"
                     BorderBrush="Transparent"
                     BorderThickness="0"
                     MaxWidth="300"
                     HorizontalContentAlignment="Stretch"
                     ScrollViewer.CanContentScroll="False"
                     ItemContainerStyle="{StaticResource poiListItemStyle}"
                     x:Name="poiList">
                </ListBox>
                <Grid Grid.Row="1"
                      Background="{StaticResource AppAlter1LightestBrush}">
                    <Button Grid.Column="0" Content="new" 
                            Command="{Binding NewPoiCommand}"
                            FontSize="16"
                            Width="100"
                            HorizontalAlignment="Right"/>
                </Grid>
            </Grid>

            <Border Margin="-1,0,0,0"
                    Grid.Column="1"
                    BorderThickness="5,0,0,0"
                    BorderBrush="{StaticResource AppBaseBrush}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition Height="50"/>
                    </Grid.RowDefinitions>

                    <Grid x:Name="poiMainGrid"
                          DataContext="{Binding SelectedPoi}"
                              Background="{StaticResource AppBaseLightestBrush}">
                        <Grid.RowDefinitions>
                            <RowDefinition  Height="30"/>
                            <RowDefinition  Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>

                        <Grid Background="{StaticResource AppBaseBrush}">
                            <TextBlock Text="poi editor"
                                       FontFamily="Segoe UI Light"
                                       FontSize="18"
                                       Margin="5,0,0,0"
                                       Foreground="White"/>
                        </Grid>

                        <Grid Grid.Row="1">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="17"/>
                                <RowDefinition Height="30"/>
                            </Grid.RowDefinitions>
                            <TextBlock Text="name:"
                                       Margin="5,0,0,0"
                                       Foreground="Gray"/>
                            <TextBox Text="{Binding Name, Mode=TwoWay}"
                                     Grid.Row="1"
                                     TextWrapping="Wrap"
                                     FontSize="14"
                                     Margin="5,0,5,5"
                                     VerticalContentAlignment="Center"
                                     FontFamily="Segoe UI Light"/>
                        </Grid>


                        <Grid Grid.Row="2">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="17"/>
                                <RowDefinition Height="30"/>
                                <RowDefinition Height="40"/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <TextBlock Text="longitude:"
                                        Foreground="Gray"
                                        Grid.Column="0"
                                        Margin="5,0,0,0"
                                        Grid.Row="0" />
                            <!--Text="{Binding DataContext.SelectedLongitude, Mode=TwoWay, ElementName=mainGrid, ValidatesOnExceptions=True, UpdateSourceTrigger=PropertyChanged}"-->
                            <TextBox Style="{DynamicResource validationTextbox}"
                                     Grid.Row="1"
                                     Grid.Column="0"
                                     Margin="5,0,5,5"
                                     VerticalContentAlignment="Center"
                                     FontSize="14" >
                                <TextBox.Text>
                                    <Binding  Path="DataContext.SelectedLongitude" Mode="TwoWay" ElementName="mainGrid" ValidatesOnExceptions="True" UpdateSourceTrigger="PropertyChanged">
                                        <Binding.ValidationRules>
                                            <logic:CoordinateValidation ValidatesOnTargetUpdated="True"/>
                                        </Binding.ValidationRules>
                                    </Binding>
                                </TextBox.Text>
                            </TextBox>

                            <TextBlock Text="latitude:" 
                                       Grid.Row="0"
                                       Foreground="Gray"
                                       Margin="5,0,0,0"
                                       Grid.Column="1"
                                        />

                            <TextBox Style="{DynamicResource validationTextbox}"
                                     Grid.Row="1"
                                     Grid.Column="1"
                                     Margin="5,0,5,5"
                                     VerticalContentAlignment="Center"
                                     FontSize="14">
                                <TextBox.Text>
                                    <Binding  Path="DataContext.SelectedLatitude" Mode="TwoWay" ElementName="mainGrid" ValidatesOnExceptions="True" UpdateSourceTrigger="PropertyChanged">
                                        <Binding.ValidationRules>
                                            <logic:CoordinateValidation ValidatesOnTargetUpdated="True"/>
                                        </Binding.ValidationRules>
                                    </Binding>
                                </TextBox.Text>
                            </TextBox>
                                
                            <Button Grid.Row="2"
                                    Grid.ColumnSpan="2"
                                    Width="150"
                                    Content="position from map"
                                    Command="{Binding DataContext.SetPoiLocationCommand, ElementName=mainGrid}"
                                    CommandParameter="{Binding DataContext, ElementName=poiMainGrid}"/>
                        </Grid>



                        <Grid Grid.Row="3">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="17"/>
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            <TextBlock Text="description:"
                                       Margin="5,0,0,0"
                                       Foreground="Gray"/>
                            <TextBox Text="{Binding Description, Mode=TwoWay}"
                                     Grid.Row="1"
                                     TextWrapping="Wrap"
                                     Margin="5,0,5,5"/>
                        </Grid>

                    </Grid>

                    <Grid Grid.Row="1"
                      Background="{StaticResource AppAlter1LightestBrush}">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>

                        <Button Grid.Column="0" Content="save" 
                                Command="{Binding SavePoiCommand}"
                                FontSize="16"
                                Width="100"/>
                        <Button Grid.Column="1" Content="delete" 
                                Command="{Binding DeletePoiCommand}"
                                CommandParameter="{Binding SelectedItem, ElementName=poiList}"
                                FontSize="16"
                                Width="100"/>
                    </Grid>
                </Grid>

            </Border>

        </Grid>

        <!--BingMapView-->
        <Grid Grid.Column="1">
            <bing:Map CredentialsProvider="Aoa1v3rq4CwdNXLnP7PaD2mQB7ZeX_RRVhgh57nJHW-TRicViXcasM8XLenxnVKK"
                      Center="{Binding MapCenter, Mode=TwoWay}">
                <bing:Pushpin Location="{Binding SelectedPoi.Position}" Visibility="{Binding PushpinVisible}"/>
            </bing:Map>
            <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
                <Line X1="-10" X2="10" Stroke="Red" StrokeThickness="1"/>
                <Line Y1="-10" Y2="10" Stroke="Red" StrokeThickness="1"/>
            </Grid>
        </Grid>
    </Grid>
</UserControl>
